package com.wisewin.pose.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSONObject;
import com.wisewin.pose.api.controller.WechatController;
import com.wisewin.pose.entity.db.MuscleDO;
import com.wisewin.pose.entity.db.UserPhysicalActionScoreDO;
import com.wisewin.pose.entity.db.UserPhysicalActionTrendDO;
import com.wisewin.pose.entity.db.UserPhysicalHealthDO;
import com.wisewin.pose.entity.db.UserPhysicalRecordDO;
import com.wisewin.pose.entity.dto.ActionTrendDTO;

public class ScoreUtil {

        final static Logger log = LoggerFactory.getLogger(WechatController.class);

        public static int gen(int max) {
                Random random = new Random();
                return random.nextInt(max) - 3;
        }

        private static int calculateAverage(UserPhysicalActionScoreDO row) {
                return (int) Arrays.stream(new int[] {
                                row.getMotionRangeLeft(), row.getMotionRangeRight(),
                                row.getMotionStabilityLeft(), row.getMotionStabilityRight(),
                                row.getMotionSymmetry()
                }).average().orElse(0);
        }

        private static int calcScore(int s) {
                int score = s + gen(7);

                return score >= 0 ? Math.min(100, score) : 0;
        }

        public static void calcAverageScore(List<UserPhysicalActionScoreDO> scoreDOs,
                        UserPhysicalRecordDO userPhysicalRecordDO) {
                if (scoreDOs != null) {
                        // 计算分数
                        int motionRangeScore = (int) scoreDOs.stream().flatMapToInt(score -> Arrays
                                        .stream(new int[] { score.getMotionRangeLeft(), score.getMotionRangeRight() }))
                                        .average().orElse(0);
                        userPhysicalRecordDO.setMotionRangeScore(calcScore(motionRangeScore));
                        int stabilityScore = (int) scoreDOs.stream()
                                        .flatMapToInt(score -> Arrays.stream(new int[] { score.getMotionStabilityLeft(),
                                                        score.getMotionStabilityRight() }))
                                        .average().orElse(0);
                        userPhysicalRecordDO.setStabilityScore(calcScore(stabilityScore));
                        int symmetryScore = (int) scoreDOs.stream()
                                        .mapToInt(UserPhysicalActionScoreDO::getMotionSymmetry)
                                        .average().orElse(0);
                        userPhysicalRecordDO.setSymmetryScore(calcScore(symmetryScore));
                        int overallScore = (motionRangeScore + stabilityScore + symmetryScore) / 3;
                        userPhysicalRecordDO.setOverallScore(calcScore(overallScore));
                        // 计算风险项
                        scoreDOs.forEach(row -> {
                                int score = calculateAverage(row);
                                switch (row.getBodyPartType()) {
                                        case "neck":
                                                userPhysicalRecordDO.setNeckRiskValue(calcScore(100 - score));
                                                break;
                                        case "upper_arm":
                                                userPhysicalRecordDO.setUpperArmRiskValue(calcScore(100 - score));
                                                break;
                                        case "trunk":
                                                userPhysicalRecordDO.setTrunkRiskValue(calcScore(100 - score));
                                                break;
                                        case "hips":
                                                userPhysicalRecordDO.setHipsRiskValue(calcScore(100 - score));
                                        case "legs":
                                                userPhysicalRecordDO.setLegsRiskValue(calcScore(100 - score));
                                        default:
                                                break;
                                }
                        });
                        int overallRiskRcore = (int) Arrays.stream(new int[] {
                                        userPhysicalRecordDO.getNeckRiskValue(),
                                        userPhysicalRecordDO.getUpperArmRiskValue(),
                                        userPhysicalRecordDO.getTrunkRiskValue(),
                                        userPhysicalRecordDO.getHipsRiskValue(),
                                        userPhysicalRecordDO.getLegsRiskValue()
                        }).average().orElse(0);
                        userPhysicalRecordDO.setOverallRiskScore(calcScore(overallRiskRcore));

                }
        }

        public static void processActionTrends(String key, List<UserPhysicalActionTrendDO> trends,
                        ActionTrendDTO[] trendDTOs) {
                switch (key) {
                        case "firstAction": {
                                List<Double> neckFlexionFront = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMaxNeckDegree)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("颈部前屈-颈部前屈");
                                actionTrendDTO.setSeriesData(neckFlexionFront);
                                trendDTOs[0] = actionTrendDTO;
                                break;

                        }
                        case "secondAction": {
                                List<Double> neckFlexionBack = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMaxNeckDegree)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("颈部后仰-颈部后仰");
                                actionTrendDTO.setSeriesData(neckFlexionBack);
                                trendDTOs[1] = actionTrendDTO;
                                break;
                        }
                        case "thirdAction": {
                                List<Double> neckLeft = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMaxSideBendAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("颈部左倾-颈部左侧弯曲");
                                actionTrendDTO.setSeriesData(neckLeft);
                                trendDTOs[2] = actionTrendDTO;
                                break;
                        }
                        case "fourthAction": {
                                List<Double> neckRight = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMaxSideBendAngle)
                                                .collect(Collectors.toList());
                                System.out.println(" action " + neckRight);
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("颈部右倾-颈部右侧弯曲");
                                actionTrendDTO.setSeriesData(neckRight);
                                trendDTOs[3] = actionTrendDTO;
                                break;
                        }
                        case "fifthAction": {
                                // 墙上天右侧
                                List<Double> shoulderRight = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getShoulderRightAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("墙上天使-右肩冠状面外展");
                                actionTrendDTO.setSeriesData(shoulderRight);
                                trendDTOs[4] = actionTrendDTO;
                                // 墙上天左侧
                                List<Double> shoulderLeft = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getShoulderLeftAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO2 = new ActionTrendDTO();
                                actionTrendDTO2.setLabelName("墙上天使-左肩冠状面外展");
                                actionTrendDTO2.setSeriesData(shoulderLeft);
                                trendDTOs[5] = actionTrendDTO2;
                                break;
                        }
                        case "sixthAction": {
                                List<Double> trunk = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getTorsoAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("直立转体-左-脊柱左旋");
                                actionTrendDTO.setSeriesData(trunk);
                                trendDTOs[6] = actionTrendDTO;
                                break;
                        }
                        case "seventhAction": {
                                List<Double> trunk = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getTorsoAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("直立转体-右-脊柱右旋");
                                actionTrendDTO.setSeriesData(trunk);
                                trendDTOs[7] = actionTrendDTO;
                                break;
                        }
                        case "ninthAction": {
                                // 过顶深蹲-右髋活动度
                                List<Double> hipRight = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMinHipRightAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("过顶深蹲-右髋活动度");
                                actionTrendDTO.setSeriesData(hipRight);
                                trendDTOs[8] = actionTrendDTO;
                                // 过顶深蹲-左髋活动度
                                List<Double> hipLeft = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMinHipLeftAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO2 = new ActionTrendDTO();
                                actionTrendDTO2.setLabelName("过顶深蹲-左髋活动度");
                                actionTrendDTO2.setSeriesData(hipLeft);
                                trendDTOs[9] = actionTrendDTO2;
                                // 过顶深蹲-右膝活动度
                                List<Double> legRight = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMinLegRightAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO3 = new ActionTrendDTO();
                                actionTrendDTO3.setLabelName("过顶深蹲-右膝活动度");
                                actionTrendDTO3.setSeriesData(legRight);
                                trendDTOs[10] = actionTrendDTO3;
                                // 过顶深蹲-左膝活动度
                                List<Double> legLeft = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMinLegRightAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO4 = new ActionTrendDTO();
                                actionTrendDTO4.setLabelName("过顶深蹲-左膝活动度");
                                actionTrendDTO4.setSeriesData(legLeft);
                                trendDTOs[11] = actionTrendDTO4;

                                break;
                        }
                        case "tennthAction": {
                                // 侧弓步-右髋活动度
                                List<Double> hipRight = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMaxHipRightAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO = new ActionTrendDTO();
                                actionTrendDTO.setLabelName("侧弓步-右髋活动度");
                                actionTrendDTO.setSeriesData(hipRight);
                                trendDTOs[12] = actionTrendDTO;
                                // 侧弓步-左髋活动度
                                List<Double> hipLeft = trends.stream()
                                                .map(UserPhysicalActionTrendDO::getMaxHipLeftAngle)
                                                .collect(Collectors.toList());
                                ActionTrendDTO actionTrendDTO2 = new ActionTrendDTO();
                                actionTrendDTO2.setLabelName("侧弓步-左髋活动度");
                                actionTrendDTO2.setSeriesData(hipLeft);
                                trendDTOs[13] = actionTrendDTO2;

                                break;
                        }
                        default:
                                break;
                }

        }

        private static UserPhysicalActionScoreDO createUserPhysicalActionScore(Integer recordId, Integer userId,
                        String actionName,
                        String actionType) {
                UserPhysicalActionScoreDO scoreDO = new UserPhysicalActionScoreDO();
                scoreDO.setRecordId(recordId);
                scoreDO.setUserId(userId);
                scoreDO.setBodyPartName(actionName);
                scoreDO.setBodyPartType(actionType);
                return scoreDO;
        }

        public static Float opFloat(JSONObject obj, String key) {
                return obj.getFloat(key);
        }

        private static MuscleDO createMuscleDO(String name, String side, String no) {
                MuscleDO muscleDO = new MuscleDO();
                muscleDO.setName(name);
                muscleDO.setNo(no);
                muscleDO.setSide(side);
                return muscleDO;
        }

        // 处理肌肉
        public static Map<String, List<MuscleDO>> dealUserMuscleDOs(Integer recordId, Integer userId,
                        Map<String, JSONObject> resultMap) {
                List<MuscleDO> tension = new ArrayList<>(); // 肌力紧张
                List<MuscleDO> weakness = new ArrayList<>(); // 肌力不足
                Map<String, List<MuscleDO>> muscleDOs = new HashMap<>();
                // 数据
                JSONObject obj1 = resultMap.get("firstAction");
                JSONObject obj2 = resultMap.get("secondAction");
                JSONObject obj3 = resultMap.get("thirdAction");
                JSONObject obj4 = resultMap.get("fourthAction");
                JSONObject obj5 = resultMap.get("fifthAction");
                JSONObject obj6 = resultMap.get("sixthAction");
                JSONObject obj7 = resultMap.get("seventhAction");
                JSONObject obj8 = resultMap.get("eighthAction");
                JSONObject obj9 = resultMap.get("ninthAction");
                JSONObject obj10 = resultMap.get("tenthAction");
                JSONObject obj11 = resultMap.get("eleventhAction");
                if (obj1 != null) {
                        Float maxDegree = opFloat(obj1, "maxNeckDegree");
                        // 30~70°
                        if (maxDegree < 30) {
                                tension.add(createMuscleDO("上斜方肌(左)", "back", "M02"));
                                tension.add(createMuscleDO("上斜方肌(右)", "back", "M04"));
                        } else if (maxDegree > 70) {
                                weakness.add(createMuscleDO("颈长肌(左)", "front", "M107"));
                                weakness.add(createMuscleDO("颈长肌(右)", "front", "M110"));
                        }
                }
                if (obj2 != null) {
                        Float maxDegree = opFloat(obj2, "maxNeckDegree");
                        // 30~60°
                        if (maxDegree < 30) {
                                tension.add(createMuscleDO("胸锁乳突肌(右)", "front", "M44"));
                                tension.add(createMuscleDO("胸锁乳突肌(左)", "front", "M43"));
                        } else if (maxDegree > 60) {
                                weakness.add(createMuscleDO("竖脊肌(左)", "front", "M63"));
                                weakness.add(createMuscleDO("竖脊肌(右)", "front", "M64"));
                        }
                }
                if (obj3 != null) {
                        Float maxDegree = opFloat(obj3, "maxSideBendAngle");
                        // 20~40°
                        if (maxDegree < 20) {
                                tension.add(createMuscleDO("胸锁乳突肌(左)", "front", "M43"));
                                // tension.add(createMuscleDO("斜角肌(左)", "front", "M95"));
                        } else if (maxDegree > 40) {
                                weakness.add(createMuscleDO("胸锁乳突肌(右)", "front", "M44"));
                                // weakness.add(createMuscleDO("多裂肌(右)", "back", "M102"));
                        }
                }
                if (obj4 != null) {
                        Float maxDegree = opFloat(obj4, "maxSideBendAngle");
                        // 20~40°
                        if (maxDegree < 20) {
                                tension.add(createMuscleDO("胸锁乳突肌(右)", "front", "M44"));
                                // tension.add(createMuscleDO("斜角肌(右)", "front", "M96"));
                        } else if (maxDegree > 40) {
                                weakness.add(createMuscleDO("胸锁乳突肌(左)", "front", "M43"));
                                // weakness.add(createMuscleDO("多裂肌(左)", "back", "M101"));
                        }
                }
                if (obj5 != null) {
                        Float leftMaxDegree = opFloat(obj5, "maxShoulderLeftAngle");
                        // 70~180°
                        if (leftMaxDegree < 70) {
                                tension.add(createMuscleDO("胸大肌(左)", "front", "M15"));
                                // tension.add(createMuscleDO("背阔肌(左)", "back", "M17"));
                        } else if (leftMaxDegree > 180) {
                                weakness.add(createMuscleDO("冈下肌（左)", "back", "M47"));
                                // weakness.add(createMuscleDO("三角肌后束（左）", "back", "M06"));
                        }
                        Float rightMaxDegree = opFloat(obj5, "maxShoulderRightAngle");
                        // 70~180°
                        if (rightMaxDegree < 70) {
                                tension.add(createMuscleDO("胸大肌（右）", "front", "M16"));
                                // tension.add(createMuscleDO("背阔肌(右)", "back", "M18"));
                        } else if (rightMaxDegree > 180) {
                                weakness.add(createMuscleDO("冈下肌（右)", "back", "M48"));
                                // weakness.add(createMuscleDO("三角肌后束（右）", "back", "M08"));
                        }
                }
                if (obj6 != null) {
                        Float maxDegree = opFloat(obj6, "torsoAngle");
                        // 15~75°
                        if (maxDegree < 15) {
                                tension.add(createMuscleDO("腹内斜肌（右)", "front", "M22"));
                                // tension.add(createMuscleDO("竖脊肌(右)", "front", "M64"));
                        } else if (maxDegree > 75) {
                                weakness.add(createMuscleDO("腹外斜肌（左）", "front", "M19"));
                                // weakness.add(createMuscleDO("腰方肌（左)", "back", "M97"));
                        }
                }
                if (obj7 != null) {
                        Float maxDegree = opFloat(obj7, "torsoAngle");
                        // 15~75°
                        if (maxDegree < 15) {
                                tension.add(createMuscleDO("腹内斜肌（左)", "front", "M20"));
                                // tension.add(createMuscleDO("竖脊肌(左)", "front", "M63"));
                        } else if (maxDegree > 75) {
                                weakness.add(createMuscleDO("腹外斜肌（右）", "front", "M21"));
                                // weakness.add(createMuscleDO("腰方肌（右)", "back", "M98"));
                        }
                }
                if (obj9 != null) {
                        Float hipLeft = opFloat(obj9, "minHipLeftAngle");
                        // 50~120°
                        if (180 - Math.abs(hipLeft) < 50) {
                                tension.add(createMuscleDO("臀大肌(左)", "back", "M29"));
                                // tension.add(createMuscleDO("股直肌(左)", "front", "M37"));
                        } else if (180 - Math.abs(hipLeft) > 120) {
                                weakness.add(createMuscleDO("臀中肌(左)", "back", "M65"));
                                // weakness.add(createMuscleDO("股薄肌（左)", "front", "M131"));
                        }
                        Float hipRight = opFloat(obj9, "minHipLeftAngle");
                        // 50~120°
                        if (180 - Math.abs(hipRight) < 50) {
                                tension.add(createMuscleDO("臀大肌(右)", "back", "M30"));
                                // tension.add(createMuscleDO("股直肌(右)", "front", "M38"));
                        } else if (180 - Math.abs(hipLeft) > 120) {
                                weakness.add(createMuscleDO("臀中肌(右)", "back", "M66"));
                                // weakness.add(createMuscleDO("股薄肌（右)", "front", "M132"));
                        }
                        // 左膝
                        Float maxDegreeLeft = opFloat(obj9, "minLegLeftAngle");
                        // 75~150°
                        if (maxDegreeLeft < 75) {
                                tension.add(createMuscleDO("股二头肌(左) ", "back", "M39"));
                        } else if (maxDegreeLeft > 150) {
                                weakness.add(createMuscleDO("股内侧肌(左）", "front", "M33"));
                                // weakness.add(createMuscleDO("股外侧肌(左)", "front", "M35"));
                        }
                        // 右膝
                        Float maxDegreeRight = opFloat(obj9, "minLegRightAngle");
                        // 75~150°
                        if (maxDegreeRight < 75) {
                                tension.add(createMuscleDO("股二头肌(右)", "back", "M40"));
                        } else if (maxDegreeRight > 150) {
                                weakness.add(createMuscleDO("股内侧肌(右）", "front", "M34"));
                                // weakness.add(createMuscleDO("股外侧肌(右)", "front", "M36"));
                        }
                }
                if (obj10 != null) {
                        Float hipLeft = opFloat(obj10, "maxHipLeftAngle");
                        // 50~120°
                        if (hipLeft < 50) {
                                tension.add(createMuscleDO("髂腰肌(左) ", "front", "M25"));
                                // tension.add(createMuscleDO("阔筋膜张肌(左) ", "front", "M31"));
                        } else if (hipLeft > 120) {
                                weakness.add(createMuscleDO("臀大肌(左)", "back", "M29"));
                                // weakness.add(createMuscleDO("臀中肌(左)", "back", "M65"));
                        }
                        Float hipRight = opFloat(obj10, "maxHipRightAngle");
                        // 50~120°
                        if (hipRight < 50) {
                                tension.add(createMuscleDO("髂腰肌(右) ", "front", "M26"));
                                // tension.add(createMuscleDO("阔筋膜张肌(右) ", "front", "M32"));
                        } else if (hipRight > 120) {
                                weakness.add(createMuscleDO("臀大肌(右)", "back", "M30"));
                                // weakness.add(createMuscleDO("臀中肌(右)", "back", "M66"));
                        }
                }

                muscleDOs.put("tension", tension);
                muscleDOs.put("weakness", weakness);
                return muscleDOs;
        }

        // 处理动作分数
        public static List<UserPhysicalActionScoreDO> dealUserPhysicalActionScore(Integer recordId, Integer userId,
                        Map<String, JSONObject> resultMap, Map<String, Map<String, Map<String, Integer>>> bodyScores) {
                // 数据
                JSONObject obj1 = resultMap.get("firstAction");
                JSONObject obj2 = resultMap.get("secondAction");
                JSONObject obj3 = resultMap.get("thirdAction");
                JSONObject obj4 = resultMap.get("fourthAction");
                JSONObject obj5 = resultMap.get("fifthAction");
                JSONObject obj6 = resultMap.get("sixthAction");
                JSONObject obj7 = resultMap.get("seventhAction");
                JSONObject obj8 = resultMap.get("eighthAction");
                JSONObject obj9 = resultMap.get("ninthAction");
                JSONObject obj10 = resultMap.get("tenthAction");
                JSONObject obj11 = resultMap.get("eleventhAction");

                // 旋转角度 标准值 (角度)
                final int NECK_STD = 45; // 颈部标准值
                final int SHOULDER_STD = 180; // 肩部标准值
                final int TRUNK_STD = 75; // 躯干标准值
                final int HIPS_STD = 120; // 骨盆标准值
                final int LEG_STD = 50; // 腿部标准值
                // 稳定性 标准值(距离)
                final int STABILITY_NECK_STD = 10;
                final int STABILITY_NECK_MAX = 20;
                final int STABILITY_SHOULDER_STD = 60;
                final int STABILITY_SHOULDER_MAX = 90;
                final int STABILITY_TRUNK_STD = 50;
                final int STABILITY_TRUNK_MAX = 90;
                final int STABILITY_HIPS_STD = 30;
                final int STABILITY_HIPS_MAX = 60;
                final int STABILITY_LEG_STD = 30;
                final int STABILITY_LEG_MAX = 60;
                // 数据
                List<UserPhysicalActionScoreDO> lstScore = new ArrayList<>();
                UserPhysicalActionScoreDO neck = createUserPhysicalActionScore(recordId, userId, "颈部", "neck");
                UserPhysicalActionScoreDO shoulder = createUserPhysicalActionScore(recordId, userId, "肩部上肢",
                                "upper_arm");
                UserPhysicalActionScoreDO trunk = createUserPhysicalActionScore(recordId, userId, "躯干", "trunk");
                UserPhysicalActionScoreDO hips = createUserPhysicalActionScore(recordId, userId, "骨盆", "hips");
                UserPhysicalActionScoreDO leg = createUserPhysicalActionScore(recordId, userId, "下肢", "legs");

                // 颈部 稳定性
                int stabilityEyeLeftScore_1 = 0;
                int stabilityEyeRightScore_1 = 0;
                int stabilityEyeLeftScore_2 = 0;
                int stabilityEyeRightScore_2 = 0;
                int stabilityEyeLeftScore_5 = 0;
                int stabilityEyeRightScore_5 = 0;
                int stabilityEyeLeftScore_8 = 0;
                int stabilityEyeRightScore_8 = 0;

                // 颈部 对称性
                int symmetryEyeScore_1 = 0;
                int symmetryEyeScore_2 = 0;
                int symmetryEyeScore_5 = 0;
                int symmetryEyeScore_9 = 0;
                int symmetryEyeScore_11 = 0;

                // 肩部 左右活动度
                int motionRangeLeftShoulderScore_5 = 0;
                int motionRangeLeftShoulderScore_9 = 0;
                int motionRangeRightShoulderScore_5 = 0;
                int motionRangeRightShoulderScore_9 = 0;

                // 肩部 稳定性
                int stabilityShoulderLeftScore_5 = 0;
                int stabilityShoulderRightScore_5 = 0;
                int stabilityShoulderLeftScore_8 = 0;
                int stabilityShoulderRightScore_8 = 0;

                // 肩部 对称性
                int symmetryShoulderScore_5 = 0;
                int symmetryShoulderScore_8 = 0;
                int symmetryShoulderScore_11 = 0;

                // 躯干 稳定性
                int stabilityLeftTrunkValueScore_5 = 0;
                int stabilityRightTrunkValueScore_5 = 0;
                int stabilityLeftTrunkValueScore_9 = 0;
                int stabilityRightTrunkValueScore_9 = 0;
                int stabilityLeftTrunkValueScore_11 = 0;
                int stabilityRightTrunkValueScore_11 = 0;

                // 躯干 对称性
                int symmetryTrunkScore_5 = 0;
                int symmetryTrunkScore_8 = 0;
                int symmetryTrunkScore_9 = 0;
                int symmetryTrunkScore_10 = 0;
                int symmetryTrunkScore_11 = 0;

                // 骨盆 左右活动度
                int motionRangeLeftHipsScore_9 = 0;
                int motionRangeRightHipsScore_9 = 0;
                int motionRangeLeftHipsScore_10 = 0;
                int motionRangeRightHipsScore_10 = 0;

                // 骨盆 对称性
                int symmetryHipsScore_8 = 0;
                int symmetryHipsScore_9 = 0;
                int symmetryHipsScore_10 = 0;
                int symmetryHipsScore_11 = 0;

                // 骨盆 稳定性
                int stabilityHipsLeftScore_8 = 0;
                int stabilityHipsRightScore_8 = 0;
                int stabilityHipsLeftScore_9 = 0;
                int stabilityHipsRightScore_9 = 0;
                int stabilityHipsLeftScore_11 = 0;
                int stabilityHipsRightScore_11 = 0;

                // 腿部 左右活动度
                int motionRangeLeftLegScore_9 = 0;
                int motionRangeRightLegScore_9 = 0;

                // 腿部 对称性
                int symmetryLegScore_9 = 0;
                int symmetryLegScore_11 = 0;

                // 腿部 稳定性
                int stabilityLeftKneeValueScore_8 = 0;
                int stabilityRightKneeValueScore_8 = 0;
                int stabilityLeftKneeValueScore_9 = 0;
                int stabilityRightKneeValueScore_9 = 0;
                int stabilityLeftKneeValueScore_11 = 0;
                int stabilityRightKneeValueScore_11 = 0;

                if (obj1 != null) {
                        //
                        symmetryEyeScore_1 = (int) obj1.getFloatValue("stabilityEyeScore");
                        //
                        stabilityEyeLeftScore_1 = ScoreUtil.calcDescScore(obj1.getFloatValue("stabilityLeftEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);
                        stabilityEyeRightScore_1 = ScoreUtil.calcDescScore(obj1.getFloatValue("stabilityRightEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);

                }

                if (obj2 != null) {
                        //
                        symmetryEyeScore_2 = (int) obj2.getFloatValue("stabilityEyeScore");
                        //
                        stabilityEyeLeftScore_2 = ScoreUtil.calcDescScore(obj2.getFloatValue("stabilityLeftEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);
                        stabilityEyeRightScore_2 = ScoreUtil.calcDescScore(obj2.getFloatValue("stabilityRightEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);

                }
                if (obj3 != null) {
                        // 颈部左活动度
                        float angle = obj3.getFloatValue("maxSideBendAngle");
                        int neckLeft = ScoreUtil.calcRotationScore(angle, NECK_STD);
                        neck.setMotionRangeLeft(neckLeft);

                }
                if (obj4 != null) {
                        // 颈部右活动度
                        float angle = obj4.getFloatValue("maxSideBendAngle");
                        int neckRight = ScoreUtil.calcRotationScore(angle, NECK_STD);
                        neck.setMotionRangeRight(neckRight);

                }

                if (obj5 != null) {
                        //
                        symmetryEyeScore_5 = (int) obj5.getFloatValue("stabilityEyeScore");
                        //
                        motionRangeLeftShoulderScore_5 = ScoreUtil
                                        .calcRotationScore(obj5.getFloatValue("maxShoulderLeftAngle"), SHOULDER_STD);
                        motionRangeRightShoulderScore_5 = ScoreUtil.calcRotationScore(
                                        obj5.getFloatValue("maxShoulderRightAngle"),
                                        SHOULDER_STD);
                        //
                        symmetryShoulderScore_5 = (int) obj5.getFloatValue("stabilityShoulderScore");
                        //
                        symmetryTrunkScore_5 = (int) obj5.getFloatValue("stabilityTrunkScore");
                        //
                        stabilityEyeLeftScore_5 = ScoreUtil.calcDescScore(obj5.getFloatValue("stabilityLeftEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);
                        stabilityEyeRightScore_5 = ScoreUtil.calcDescScore(obj5.getFloatValue("stabilityRightEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);
                        //
                        stabilityShoulderLeftScore_5 = ScoreUtil.calcDescScore(
                                        obj5.getFloatValue("stabilityLeftShoulderValue"),
                                        STABILITY_SHOULDER_STD, STABILITY_SHOULDER_MAX);
                        stabilityShoulderRightScore_5 = ScoreUtil.calcDescScore(
                                        obj5.getFloatValue("stabilityRightShoulderValue"),
                                        STABILITY_SHOULDER_STD, STABILITY_SHOULDER_MAX);
                        //
                        stabilityLeftTrunkValueScore_5 = ScoreUtil.calcDescScore(
                                        obj5.getFloatValue("stabilityLeftTrunkValue"),
                                        STABILITY_TRUNK_STD, STABILITY_TRUNK_MAX);
                        stabilityRightTrunkValueScore_5 = ScoreUtil.calcDescScore(
                                        obj5.getFloatValue("stabilityRightTrunkValue"),
                                        STABILITY_TRUNK_STD, STABILITY_TRUNK_MAX);
                }

                if (obj6 != null) {
                        // 躯干 左活动度
                        float angle = obj6.getFloatValue("torsoAngle");
                        int trunkLeft = ScoreUtil.calcRotationScore(angle, TRUNK_STD);
                        trunk.setMotionRangeLeft(trunkLeft);
                }
                if (obj7 != null) {
                        // 躯干 右活动度
                        float angle = obj7.getFloatValue("torsoAngle");
                        int trunkRight = ScoreUtil.calcRotationScore(angle, TRUNK_STD);
                        trunk.setMotionRangeRight(trunkRight);
                }

                if (obj8 != null) {
                        //
                        symmetryShoulderScore_8 = (int) obj8.getFloatValue("stabilityShoulderScore");
                        //
                        symmetryTrunkScore_8 = (int) obj8.getFloatValue("stabilityTrunkScore");
                        //
                        symmetryHipsScore_8 = (int) obj8.getFloatValue("stabilityHipScore");
                        //
                        stabilityEyeLeftScore_8 = ScoreUtil.calcDescScore(obj8.getFloatValue("stabilityLeftEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);
                        stabilityEyeRightScore_8 = ScoreUtil.calcDescScore(obj8.getFloatValue("stabilityRightEye"),
                                        STABILITY_NECK_STD, STABILITY_NECK_MAX);
                        //
                        stabilityShoulderLeftScore_8 = ScoreUtil.calcDescScore(
                                        obj8.getFloatValue("stabilityLeftShoulderValue"),
                                        STABILITY_SHOULDER_STD, STABILITY_SHOULDER_MAX);
                        stabilityShoulderRightScore_8 = ScoreUtil.calcDescScore(
                                        obj8.getFloatValue("stabilityRightShoulderValue"),
                                        STABILITY_SHOULDER_STD, STABILITY_SHOULDER_MAX);
                        //
                        stabilityHipsLeftScore_8 = ScoreUtil.calcDescScore(obj8.getFloatValue("stabilityLeftHipValue"),
                                        STABILITY_HIPS_STD, STABILITY_HIPS_MAX);
                        stabilityHipsRightScore_8 = ScoreUtil.calcDescScore(
                                        obj8.getFloatValue("stabilityRightHipValue"),
                                        STABILITY_HIPS_STD, STABILITY_HIPS_MAX);
                        //
                        stabilityLeftKneeValueScore_8 = ScoreUtil.calcDescScore(
                                        obj8.getFloatValue("stabilityLeftKneeValue"),
                                        STABILITY_LEG_STD, STABILITY_LEG_MAX);
                        stabilityRightKneeValueScore_8 = ScoreUtil.calcDescScore(
                                        obj8.getFloatValue("stabilityRightKneeValue"),
                                        STABILITY_LEG_STD, STABILITY_LEG_MAX);

                }

                if (obj9 != null) {
                        //
                        symmetryEyeScore_9 = (int) obj9.getFloatValue("stabilityEyeScore");
                        //
                        motionRangeLeftShoulderScore_9 = ScoreUtil.calcRotationScore(
                                        obj9.getFloatValue("maxShoulderLeftAngle"),
                                        SHOULDER_STD);
                        motionRangeLeftShoulderScore_9 = ScoreUtil.calcRotationScore(
                                        obj9.getFloatValue("maxShoulderRightAngle"),
                                        SHOULDER_STD);
                        //
                        symmetryTrunkScore_9 = (int) obj9.getFloatValue("stabilityTrunkScore");
                        //
                        motionRangeLeftHipsScore_9 = ScoreUtil.calcDescScore(obj9.getFloatValue("minHipLeftAngle"),
                                        HIPS_STD, 180);
                        motionRangeRightHipsScore_9 = ScoreUtil.calcDescScore(obj9.getFloatValue("minHipRightAngle"),
                                        HIPS_STD, 180);
                        //
                        symmetryHipsScore_9 = (int) obj9.getFloatValue("stabilityHipScore");
                        // 腿部 左右活动度
                        motionRangeLeftLegScore_9 = ScoreUtil.calcRotationScore(obj9.getFloatValue("minLegLeftAngle"),
                                        LEG_STD);
                        motionRangeRightLegScore_9 = ScoreUtil.calcRotationScore(obj9.getFloatValue("minLegRightAngle"),
                                        LEG_STD);

                        leg.setMotionRangeLeft(motionRangeLeftLegScore_9);
                        leg.setMotionRangeRight(motionRangeRightLegScore_9);

                        //
                        symmetryLegScore_9 = (int) obj9.getFloatValue("stabilityKneeScore");
                        //
                        stabilityLeftTrunkValueScore_9 = ScoreUtil.calcDescScore(
                                        obj9.getFloatValue("stabilityLeftTrunkValue"),
                                        STABILITY_TRUNK_STD, STABILITY_TRUNK_MAX);
                        stabilityRightTrunkValueScore_9 = ScoreUtil.calcDescScore(
                                        obj9.getFloatValue("stabilityRightTrunkValue"),
                                        STABILITY_TRUNK_STD, STABILITY_TRUNK_MAX);
                        //
                        stabilityHipsLeftScore_9 = ScoreUtil.calcDescScore(obj9.getFloatValue("stabilityLeftHipValue"),
                                        STABILITY_HIPS_STD, STABILITY_HIPS_MAX);
                        stabilityHipsRightScore_9 = ScoreUtil.calcDescScore(
                                        obj9.getFloatValue("stabilityRightHipValue"),
                                        STABILITY_HIPS_STD, STABILITY_HIPS_MAX);
                        //
                        stabilityLeftKneeValueScore_9 = ScoreUtil.calcDescScore(
                                        obj9.getFloatValue("stabilityLeftKneeValue"),
                                        STABILITY_LEG_STD, STABILITY_LEG_MAX);
                        stabilityRightKneeValueScore_9 = ScoreUtil.calcDescScore(
                                        obj9.getFloatValue("stabilityRightKneeValue"),
                                        STABILITY_LEG_STD, STABILITY_LEG_MAX);

                }

                if (obj10 != null) {
                        //
                        symmetryTrunkScore_10 = (int) obj10.getFloatValue("stabilityTrunkScore");
                        //
                        motionRangeLeftHipsScore_10 = ScoreUtil
                                        .calcRotationScore(obj10.getFloatValue("maxHipLeftAngle"), HIPS_STD);
                        motionRangeRightHipsScore_10 = ScoreUtil.calcRotationScore(
                                        obj10.getFloatValue("maxHipRightAngle"),
                                        HIPS_STD);
                        //
                        symmetryHipsScore_10 = (int) obj10.getFloatValue("stabilityHipScore");

                }

                if (obj11 != null) {
                        //
                        symmetryEyeScore_11 = (int) obj11.getFloatValue("stabilityEyeScore");
                        //
                        symmetryShoulderScore_11 = (int) obj11.getFloatValue("stabilityShoulderScore");
                        //
                        symmetryTrunkScore_11 = (int) obj11.getFloatValue("stabilityTrunkScore");
                        //
                        symmetryHipsScore_11 = (int) obj11.getFloatValue("stabilityHipScore");
                        //
                        symmetryLegScore_11 = (int) obj11.getFloatValue("stabilityKneeScore");
                        //
                        stabilityLeftTrunkValueScore_11 = ScoreUtil.calcDescScore(
                                        obj11.getFloatValue("stabilityLeftTrunkValue"),
                                        STABILITY_TRUNK_STD, STABILITY_TRUNK_MAX);
                        stabilityRightTrunkValueScore_11 = ScoreUtil.calcDescScore(
                                        obj11.getFloatValue("stabilityRightTrunkValue"),
                                        STABILITY_TRUNK_STD, STABILITY_TRUNK_MAX);
                        //
                        stabilityHipsLeftScore_11 = ScoreUtil.calcDescScore(
                                        obj11.getFloatValue("stabilityLeftHipValue"),
                                        STABILITY_HIPS_STD, STABILITY_HIPS_MAX);
                        stabilityHipsRightScore_11 = ScoreUtil.calcDescScore(
                                        obj11.getFloatValue("stabilityRightHipValue"),
                                        STABILITY_HIPS_STD, STABILITY_HIPS_MAX);
                        //
                        stabilityLeftKneeValueScore_11 = ScoreUtil.calcDescScore(
                                        obj11.getFloatValue("stabilityLeftKneeValue"),
                                        STABILITY_LEG_STD, STABILITY_LEG_MAX);
                        stabilityRightKneeValueScore_11 = ScoreUtil.calcDescScore(
                                        obj11.getFloatValue("stabilityRightKneeValue"),
                                        STABILITY_LEG_STD, STABILITY_LEG_MAX);
                }

                // 颈部 稳定性
                int stabilityNeckLeftScore = ScoreUtil.calculateAverage(stabilityEyeLeftScore_1,
                                stabilityEyeLeftScore_2,
                                stabilityEyeLeftScore_5, stabilityEyeLeftScore_8);
                neck.setMotionStabilityLeft(stabilityNeckLeftScore);
                int stabilityNeckRightScore = ScoreUtil.calculateAverage(stabilityEyeRightScore_1,
                                stabilityEyeRightScore_2,
                                stabilityEyeRightScore_5, stabilityEyeRightScore_8);
                neck.setMotionStabilityRight(stabilityNeckRightScore);

                // 颈部对称性
                int symmetryNeckScore = ScoreUtil.calculateAverage(symmetryEyeScore_1, symmetryEyeScore_2,
                                symmetryEyeScore_5,
                                symmetryEyeScore_9,
                                symmetryEyeScore_11);
                neck.setMotionSymmetry(symmetryNeckScore);
                // 肩部 左右活动度
                int motionRangeLeftShoulder = ScoreUtil.calculateAverage(motionRangeLeftShoulderScore_5,
                                motionRangeLeftShoulderScore_9);
                int motionRangeRightShoulder = ScoreUtil.calculateAverage(motionRangeRightShoulderScore_5,
                                motionRangeRightShoulderScore_9);
                shoulder.setMotionRangeLeft(motionRangeLeftShoulder);
                shoulder.setMotionRangeRight(motionRangeRightShoulder);
                // 肩部 对称性
                int symmetryShoulder = ScoreUtil.calculateAverage(
                                symmetryShoulderScore_5,
                                symmetryShoulderScore_8,
                                symmetryShoulderScore_11);
                shoulder.setMotionSymmetry(symmetryShoulder);
                // 肩部 稳定性
                int stabilityShoulderLeft = ScoreUtil.calculateAverage(stabilityShoulderLeftScore_5,
                                stabilityShoulderLeftScore_8);
                int stabilityShoulderRight = ScoreUtil.calculateAverage(stabilityShoulderRightScore_5,
                                stabilityShoulderRightScore_8);
                shoulder.setMotionStabilityLeft(stabilityShoulderLeft);
                shoulder.setMotionStabilityRight(stabilityShoulderRight);

                // 躯干 对称性
                int symmetryTrunk = ScoreUtil.calculateAverage(
                                symmetryTrunkScore_5,
                                symmetryTrunkScore_8,
                                symmetryTrunkScore_9, symmetryTrunkScore_10, symmetryTrunkScore_11);
                trunk.setMotionSymmetry(symmetryTrunk);

                // 躯干 稳定性
                int stabilityTrunkLeft = ScoreUtil.calculateAverage(stabilityLeftTrunkValueScore_5,
                                stabilityLeftTrunkValueScore_9, stabilityLeftTrunkValueScore_11);
                int stabilityTrunkRight = ScoreUtil.calculateAverage(stabilityRightTrunkValueScore_5,
                                stabilityRightTrunkValueScore_9, stabilityRightTrunkValueScore_11);
                trunk.setMotionStabilityLeft(stabilityTrunkLeft);
                trunk.setMotionStabilityRight(stabilityTrunkRight);

                // 骨盆 左右活动度
                int motionRangeLeftHips = ScoreUtil.calculateAverage(motionRangeLeftHipsScore_9,
                                motionRangeLeftHipsScore_10);
                int motionRangeRightHips = ScoreUtil.calculateAverage(motionRangeRightHipsScore_9,
                                motionRangeRightHipsScore_10);
                hips.setMotionRangeLeft(motionRangeLeftHips);
                hips.setMotionRangeRight(motionRangeRightHips);

                // 骨盆 对称性
                int symmetryHips = ScoreUtil.calculateAverage(
                                symmetryHipsScore_8,
                                symmetryHipsScore_9,
                                symmetryHipsScore_10,
                                symmetryHipsScore_11);
                hips.setMotionSymmetry(symmetryHips);

                // 骨盆 稳定性
                int stabilityHipsLeft = ScoreUtil.calculateAverage(stabilityHipsLeftScore_8,
                                stabilityHipsLeftScore_9, stabilityHipsLeftScore_11);
                int stabilityHipsRight = ScoreUtil.calculateAverage(stabilityHipsRightScore_8,
                                stabilityHipsRightScore_9, stabilityHipsRightScore_11);
                hips.setMotionStabilityLeft(stabilityHipsLeft);
                hips.setMotionStabilityRight(stabilityHipsRight);

                // 腿部 对称性
                int symmetryLeg = ScoreUtil.calculateAverage(symmetryLegScore_9, symmetryLegScore_11);
                leg.setMotionSymmetry(symmetryLeg);

                // 腿部 稳定性
                int stabilityLegLeft = ScoreUtil.calculateAverage(stabilityLeftKneeValueScore_8,
                                stabilityLeftKneeValueScore_9, stabilityLeftKneeValueScore_11);
                int stabilityLegRight = ScoreUtil.calculateAverage(stabilityRightKneeValueScore_8,
                                stabilityRightKneeValueScore_9, stabilityRightKneeValueScore_11);
                leg.setMotionStabilityLeft(stabilityLegLeft);
                leg.setMotionStabilityRight(stabilityLegRight);
                //
                lstScore.add(neck);
                lstScore.add(shoulder);
                lstScore.add(trunk);
                lstScore.add(hips);
                lstScore.add(leg);
                // 颈部
                Map<String, Map<String, Integer>> neckScores = new HashMap<>();
                neckScores.put("activity", new HashMap<String, Integer>() {
                        {
                                put("left", neck.getMotionRangeLeft());
                                put("right", neck.getMotionRangeRight());
                        }
                });
                neckScores.put("stability", new HashMap<String, Integer>() {
                        {
                                put("left", neck.getMotionStabilityLeft());
                                put("right", neck.getMotionStabilityRight());
                        }
                });
                neckScores.put("symmetry", new HashMap<String, Integer>() {
                        {
                                put("left", neck.getMotionSymmetry());
                                put("right", neck.getMotionSymmetry());
                        }
                });
                bodyScores.put("颈部", neckScores);
                // 肩部
                Map<String, Map<String, Integer>> shoulderScores = new HashMap<>();
                shoulderScores.put("activity", new HashMap<String, Integer>() {
                        {
                                put("left", shoulder.getMotionRangeLeft());
                                put("right", shoulder.getMotionRangeRight());
                        }
                });
                shoulderScores.put("stability", new HashMap<String, Integer>() {
                        {
                                put("left", shoulder.getMotionStabilityLeft());
                                put("right", shoulder.getMotionStabilityRight());
                        }
                });
                shoulderScores.put("symmetry", new HashMap<String, Integer>() {
                        {
                                put("left", shoulder.getMotionSymmetry());
                                put("right", shoulder.getMotionSymmetry());
                        }
                });
                bodyScores.put("肩部", shoulderScores);
                // 躯干
                Map<String, Map<String, Integer>> torsoScores = new HashMap<>();
                torsoScores.put("activity", new HashMap<String, Integer>() {
                        {
                                put("left", trunk.getMotionRangeLeft());
                                put("right", trunk.getMotionRangeRight());
                        }
                });
                torsoScores.put("stability", new HashMap<String, Integer>() {
                        {
                                put("left", trunk.getMotionStabilityLeft());
                                put("right", trunk.getMotionStabilityRight());
                        }
                });
                torsoScores.put("symmetry", new HashMap<String, Integer>() {
                        {
                                put("left", trunk.getMotionSymmetry());
                                put("right", trunk.getMotionSymmetry());
                        }
                });
                bodyScores.put("躯干", torsoScores);
                // 盆骨
                Map<String, Map<String, Integer>> pelvisScores = new HashMap<>();
                pelvisScores.put("activity", new HashMap<String, Integer>() {
                        {
                                put("left", hips.getMotionRangeLeft());
                                put("right", hips.getMotionRangeRight());
                        }
                });
                pelvisScores.put("stability", new HashMap<String, Integer>() {
                        {
                                put("left", hips.getMotionStabilityLeft());
                                put("right", hips.getMotionStabilityRight());
                        }
                });
                pelvisScores.put("symmetry", new HashMap<String, Integer>() {
                        {
                                put("left", hips.getMotionSymmetry());
                                put("right", hips.getMotionSymmetry());
                        }
                });
                bodyScores.put("骨盆", pelvisScores);
                // 下肢

                Map<String, Map<String, Integer>> lowerLimbScores = new HashMap<>();
                lowerLimbScores.put("activity", new HashMap<String, Integer>() {
                        {
                                put("left", leg.getMotionRangeLeft());
                                put("right", leg.getMotionRangeRight());
                        }
                });
                lowerLimbScores.put("stability", new HashMap<String, Integer>() {
                        {
                                put("left", leg.getMotionStabilityLeft());
                                put("right", leg.getMotionStabilityRight());
                        }
                });
                lowerLimbScores.put("symmetry", new HashMap<String, Integer>() {
                        {
                                put("left", leg.getMotionSymmetry());
                                put("right", leg.getMotionSymmetry());
                        }
                });
                bodyScores.put("下肢", lowerLimbScores);

                return lstScore;

        }

        /**
         * 计算转角分数 -> degree / std * 100
         * 
         * @param degree 角度
         * @param std    标准值
         * @return
         */
        public static int calcRotationScore(float degree, float std) {
                int s = (int) (Math.abs(degree) * 100 / std);
                return Math.min(Math.abs(s), 100);
        }

        /**
         * 从max -> std 递减 分数越高. 小于std 满分
         * 
         * @param degree 实际角度
         * @param std    标准值
         * @param max    最大值
         * @return
         */
        public static int calcDescScore(float degree, float std, int max) {
                // 大于180度为无效数据
                if (Math.abs(degree) - max > 0) {
                        return 0;
                }
                int score = (int) ((max - Math.abs(degree)) / (max - std) * 100);
                return score < 0 ? 0 : Math.min(score, 100);
        }

        /**
         * 计算平均分数
         * 
         * @param scores
         * @return
         */
        public static int calculateAverage(int... scores) {
                int sum = 0;

                // 计算总和
                for (int score : scores) {
                        sum += Math.abs(score);
                }

                // 计算平均值
                return (int) (sum / scores.length);
        }

        public Map<String, String> userPhysicalCategory() {
                Map<String, String> categoryMap = new HashMap<>();
                categoryMap.put("headLateral", "头部侧倾");
                categoryMap.put("hlShoulder", "高低肩");
                categoryMap.put("bodyTilt", "躯干偏移");
                categoryMap.put("pelvicTilt", "骨盆侧倾");
                categoryMap.put("leftLeg", "左腿评估");
                categoryMap.put("rightLeg", "右腿盖评估");
                return categoryMap;
        }

        // Method to generate the full posture assessment report
        public static String generateReport(int activityScore, int stabilityScore, int symmetryScore,
                        Map<String, Map<String, Map<String, Integer>>> bodyScores,
                        Map<String, UserPhysicalHealthDO> postureScores) {
                StringBuilder report = new StringBuilder();

                // 1. General Activity, Stability, and Symmetry Summary with Evaluation
                report.append("根据您的体态评估结果，以下是详细的指导意见：\n");

                // Activity evaluation
                if (activityScore < 60) {
                        report.append("1. 您的身体活动素质基础一般，活动度有待提升。\n");
                } else if (activityScore < 75) {
                        report.append("1. 您的身体活动素质良好，但仍有进一步提升空间。\n");
                } else {
                        report.append("1. 您的身体活动素质很优秀，保持良好的活动水平。\n");
                }

                // Stability evaluation
                if (stabilityScore < 60) {
                        report.append("2. 您的稳定性能力较弱，建议增加核心力量训练，提升整体稳定性。\n");
                } else if (stabilityScore < 75) {
                        report.append("2. 您的稳定性较好，但还可以通过训练增强耐力。\n");
                } else {
                        report.append("2. 您的力量能力水平较好，保持良好的稳定性。\n");
                }

                // Symmetry evaluation
                if (symmetryScore < 60) {
                        report.append("3. 您的身体对称性较差，建议进行对称性训练，提升左右平衡。\n");
                } else if (symmetryScore < 75) {
                        report.append("3. 您的身体对称性表现一般，建议通过训练改善左右不对称的情况。\n");
                } else {
                        report.append("3. 您的身体对称性表现优秀，继续保持。\n");
                }

                // 2. Body-Part Specific Recommendations
                // report.append("\n针对具体部位的改进建议：\n");

                // for (String bodyPart : bodyScores.keySet()) {
                // Map<String, Map<String, Integer>> partScores = bodyScores.get(bodyPart);

                // // Get the scores for each body part (activity, stability, symmetry)
                // int activityLeft = partScores.get("activity").get("left");
                // int activityRight = partScores.get("activity").get("right");
                // int stabilityLeft = partScores.get("stability").get("left");
                // int stabilityRight = partScores.get("stability").get("right");
                // int symmetryLeft = partScores.get("symmetry").get("left");
                // int symmetryRight = partScores.get("symmetry").get("right");

                // // Activity recommendations for specific body part
                // if (activityLeft < 60 || activityRight < 60) {
                // report.append("• " + bodyPart + "的活动度较弱，建议进行针对性的拉伸和柔韧性训练，尤其是左侧和右侧的活动度提升。\n");
                // }

                // // Stability recommendations for specific body part
                // if (stabilityLeft < 60 || stabilityRight < 60) {
                // report.append("• " + bodyPart + "的稳定性较差，建议加强稳定性训练，尤其是针对左侧和右侧的平衡。\n");
                // }

                // // Symmetry recommendations for specific body part
                // if (symmetryLeft < 60 || symmetryRight < 60) {
                // report.append("• " + bodyPart + "的对称性问题需要改善，建议增加平衡和协调性训练，保持左右均衡。\n");
                // }
                // }

                // 3. Posture Issues and Risk Analysis
                report.append("\n根据您的体态数据，以下是潜在的运动风险及姿势问题：\n");

                Map<String, UserPhysicalHealthDO> postureIssues = postureScores;

                StringBuffer middle = new StringBuffer();
                StringBuffer high = new StringBuffer();
                Map<String, String> risk = new HashMap<>();

                for (Map.Entry<String, UserPhysicalHealthDO> entry : postureIssues.entrySet()) {
                        String key = entry.getKey();
                        UserPhysicalHealthDO score = entry.getValue();
                        switch (score.getResult()) {
                                case "MIDDLE":
                                        // risk.put(key, score.getResult());
                                        middle.append(bodyPart(key, score));
                                        middle.append(",");
                                        break;
                                case "HIGH":
                                        risk.put(key, score.getResult());
                                        high.append(bodyPart(key, score));
                                        high.append(",");
                                        break;
                                default:
                                        break;
                        }

                }
                if (middle.length() > 0) {
                        middle.deleteCharAt(middle.length() - 1);
                        report.append("• 您的" + middle.toString() + "问题较明显，建议通过针对性训练调整，避免姿势不当导致身体不适。\n");
                }

                if (high.length() > 0) {
                        high.deleteCharAt(high.length() - 1);
                        report.append("• 您的" + high.toString() + "问题较为严重，建议进行专业矫正训练，尽早解决相关问题。\n");
                }

                // 4. Specific Health Risk Analysis
                if (!risk.isEmpty() && (risk.containsKey("bodyTilt") || risk.containsKey("pelvicTilt")
                                || risk.containsKey("headLateral"))) {
                        report.append("\n潜在健康风险分析：\n");
                }

                // Analyze specific risks based on posture data
                if (risk.containsKey("bodyTilt")) {
                        report.append("• 您有腰椎间盘突出风险，训练中应避免过度压迫和不当姿势，特别是腰部负荷较大的动作。\n");
                }

                if (risk.containsKey("pelvicTilt")) {
                        report.append("• 您的骨盆前倾较为明显，长期姿势不当可能增加脊柱负担，建议进行骨盆矫正和稳定性训练。\n");
                }

                if (risk.containsKey("headLateral") || risk.containsKey("hlShoulder")) {
                        report.append("• 您的肩部存在一定的受伤风险，建议避免过度负重，逐步增加训练强度，同时加强肩部稳定性训练。\n");
                }

                // Return the complete report
                return report.toString();
        }

        public static String bodyPart(String key, UserPhysicalHealthDO score) {
                String part = "";
                switch (key) {
                        case "headLateral":
                                part = "头部侧倾";
                                break;
                        case "hlShoulder":
                                part = "高低肩";
                                break;
                        case "bodyTilt":
                                part = "躯干偏移";
                                break;
                        case "pelvicTilt":
                                part = "骨盆侧倾";
                                break;
                        case "legBalance":
                                part = "中度失平衡";
                                break;
                        case "leftLeg":
                                part = "左腿" + score.getType();
                                break;
                        case "rightLeg":
                                part = "右腿" + score.getType();
                                break;
                        default:
                                break;
                }
                return part;
        }
}
